﻿using SqlPerfomance.V2.DAL;
using SqlPerfomance.V2.DomainModel.Enums;
using SqlPerfomance.V2.DomainModel.Models;
using SqlPerfomance.V2.DomainModel.NodeTree.Interfaces;
using SqlPerfomance.V2.Tests;
using SqlPerfomance.V2.Tests.TestsCommand;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlPerfomance.V2.ConsoleClient
{
	class Program
	{
		static void Main(string[] args)
		{



			var commonTreeRepository = new CommonTreeRepository();
			var commonTree = commonTreeRepository.CreateCommonTree(100, 4);
			///Console.WriteLine("Common tree created");
			//var alTreeRepository = new AdjancyListTreeRepository();
			//var alTree = alTreeRepository.CreateTree((INode<CommonTreeNode>)commonTree);
			//Console.WriteLine("AdjancyList Tree created");
			//var mpTreeRepository = new MaterializedPathTreeRepository();
			//var mpTree = mpTreeRepository.CreateTree((INode<CommonTreeNode>)commonTree);
			//Console.WriteLine("MaterializedPath Tree created");

			var commo = commonTree.Nodes.ToList();

			//var nsRepo = new NestedSetTreeRepository();
			//var nsTree = nsRepo.CreateTree((INode<CommonTreeNode>)commonTree);

			//var lst = nsTree.Nodes.ToList();

			//nsRepo.SaveRange(nsTree.Nodes, ConnectionStrings.SqlServerConnectionString);

			 //alTreeRepository.SaveRange(alTree.Nodes, ConnectionStrings.SqlServerConnectionString);
			//mpTreeRepository.SaveRange(mpTree.Nodes, ConnectionStrings.SqlServerConnectionString);
			//alTreeRepository.SaveRange(alTree.Nodes, ConnectionStrings.SqlServerConnectionString);
			//var tree = mpTreeRepository.GetMaterializedPathTree(ConnectionStrings.SqlServerConnectionString);


			var nsRepo = new NestedSetTreeRepository();
			nsRepo.RemoveNode(ConnectionStrings.SqlServerConnectionString, "NsTreeTable", 2);
			//var nsTree = nsRepo.CreateTree((INode<CommonTreeNode>)commonTree);

			//nsRepo.SaveRange(nsTree.Nodes, ConnectionStrings.SqlServerConnectionString);

			//nsRepo.AddChildrenNode(ConnectionStrings.SqlServerConnectionString, "NsTreeTable", 2);


            var settings = new List<TestSettings>()
			{
				new TestSettings
				{
					NestingLevel = 4,
					NodesCount = 1000
				}
			};

			var cmd = new MacroTest(ConnectionStrings.MySqlConnectionString);
			var res = cmd.Run(settings);

			string q = "";
			//Console.WriteLine("NestedSet Tree created");
			//WpfApp.XDocumentTransformer.ConvertNestedSetTreeToXml((INode<NestedSetTreeNode>)nsTree);
			//var xmlAl = WpfApp.XDocumentTransformer.ConvertAdjancyListTreeToXml((INode<AdjancyListTreeNode>)alTree);
			//xmlAl.Save(File.Create("adjancyList.xml"));
			////var xmlNs = WpfApp.XDocumentTransformer.ConvertNestedSetTreeToXml((INode<NestedSetTreeNode>)nsTree);
			////xmlNs.Save("");
			//var xmlMp = WpfApp.XDocumentTransformer.ConvertMaterializedPathTreeToXml((INode<MaterializedPathTreeNode>)mpTree);
			//xmlMp.Save(File.Create("materializedPath.xml"));

			//foreach(var node in  alTree.Nodes)
			//{
			//    alTreeRepository.NodeTreeSave(node, BLL.Enums.ConnectionStrings.SqlServerConnectionString);
			//}

			//alTreeRepository.SaveRange(alTree.Nodes, BLL.Enums.ConnectionStrings.SqlServerConnectionString);
			//mpTreeRepository.SaveRange(mpTree.Nodes, BLL.Enums.ConnectionStrings.SqlServerConnectionString);

            // alTreeRepository.SaveRange(alTree.Nodes, ConnectionStrings.SqlServerConnectionString);
            // var tree = alTreeRepository.SelectBranchById(ConnectionStrings.SqlServerConnectionString, "AlTreeTable", 2);
			 //var al = alTreeRepository.SelectChildrenById(ConnectionStrings.SqlServerConnectionString, "AlTreeTable", 2);
			// alTreeRepository.AddNodeToRootChildren(ConnectionStrings.SqlServerConnectionString, "AlTreeTable");
			// alTreeRepository.DeleteNode(ConnectionStrings.SqlServerConnectionString, "AlTreeTable", 1000001);

			 //string s = "";
			 //var alTest = new AlTests(ConnectionStrings.SqlServerConnectionString, "AlTreeTable");

			 //long test1 = alTest.TestAddNode();
			 //long test2 = alTest.TestDeleteNode();
			 //long test3 = alTest.TestMoveNode();
			 //long test4 = alTest.TestSelectAll();
			 //long test5 = alTest.TestSelectBranchById(2);
			 //long test6 = alTest.TestSelectChildrenById();
			 //long test7 = alTest.TestSelectParentById();
			 //long test8 = alTest.TestSelectPathById();

			//var mpTest = new MpTests(ConnectionStrings.SqlServerConnectionString, "MpTreeTable");

			//var t1 = mpTest.TestSelectPathById();
			//var t2 = mpTest.TestSelectParentById();
			//var t3 = mpTest.TestSelectChildrenById();
			//var t4 = mpTest.TestSelectBranchById(2);
			//var t5 = mpTest.TestSelectAll();
			//var t6 = mpTest.TestMoveNode();
			//var t7 = mpTest.TestAddNode();
			//var t8 = mpTest.TestDeleteNode();

			string s = "";
			 //long allResult = test1 + test2 + test3 + test4 + test5 + test6 + test7 + test8;

			 //string s1 = "";

			// alTreeRepository.SaveRange(alTree.Nodes, ConnectionStrings.SqlServerConnectionString);
			//nsTreeRepository.SaveRange(nsTree.Nodes, ConnectionStrings.SqlServerConnectionString);

		}
	}
}
